using SmartBoard.Core.Data;

namespace SmartBoard.Background.BoardElement
{
    internal class BackgroundDataManager:BoardElementDataManagerBase
    {
        private IBoardElementData _backgroundData;
        private readonly IBoardElementDataBroker _dataBroker;

        public BackgroundDataManager(IDataVersionConverter versionConverter, IBoardElementDataBroker dataBroker) : base(versionConverter)
        {
            _dataBroker = dataBroker;
        }

        #region Overrides of BoardElementDataManagerBase

        public override bool IsDataChanged
        {
            get
            {
                var elementData = _dataBroker.GetData();
                if (_backgroundData != null)
                {
                    return _backgroundData.Equals(elementData);
                }
                else
                {
                    return true;
                }
            }
        }

        public override byte ElementDataVersion
        {
            get { return _dataBroker.GetElementDataVersion(); }
        }

        protected override IBoardElementData DoGetData()
        {
            return _dataBroker.GetData();
        }

        protected override void DoSetData(IBoardElementData data)
        {
            _backgroundData = data;
            _dataBroker.SetData(data);
        }

        #endregion
    }
}